package com.aqie.easy.greedy;

import java.util.Arrays;

/**
 * 1029 两地调度,返回最低费用
 * 贪心算法 todo
 */
public class TwoCitySchedCost {
    //先计算出全部去A城的费用，再根据差值生成数组升序排序，获取差最小的前一半元素与A城所有费用和
    public int twoCitySchedCost(int[][] costs) {
        int result = 0;
        int[] vals = new int[costs.length];
        for (int i = 0;i < costs.length; i++){
            vals[i] = costs[i][0] - costs[i][1];
            result = result + costs[i][1];
        }
        Arrays.sort(vals);
        for (int i = 0; i < costs.length / 2;i++){
            result += vals[i];
        }
        return result;
    }

    public static void main(String[] args) {
        int[][] arr = {{10,20}, {30,200}, {400,50}, {30,20}};

    }
}
